#ifndef CPP_UPGRADE_SERVICE_H
#define CPP_UPGRADE_SERVICE_H
#include <services/UsbService.h>

//@brief 升级服务
//@author cvte
//@description 包括系统、应用、数据等升级功能
class UpgradeService {
   public:
    friend class UsbService;

    typedef enum {
        UPGRADE_TYPE_NONE,
        UPGRADE_TYPE_SYSTEM,
        UPGRADE_TYPE_APP,
        UPGRADE_TYPE_POWERBOARD,
        UPGRADE_TYPE_GENERAL_DATA,
        UPGRADE_TYPE_MISC_DATA,
    } UPGRADE_TYPE;
    class UpgradeServiceListener {
       public:
        virtual void onUdiskUpgradeExist(bool isExist); //发现U盘升级
    };

    static UpgradeService* getInstance();
    //@method 设置监听
    void setListener(UpgradeServiceListener& listener);
    //@method 进行U盘升级，检查U盘中的升级文件，退出MiniGUI程序并执行aw_upgrade_lite.sh -f命令
    void doUdiskUpgrade();
    //@method 进行OTA升级，退出MiniGUI程序并执行aw_upgrade_lite.sh -f命令
    void doOtaUpgrade();
    //@method 获取升级类型
    UPGRADE_TYPE getUpgradeType();
    //@method 获取升级描述
    const char* getUpgradeDesc();
    //@method 获取升级文件路径
    const char* getUpgradeFilePath();

   protected:
    //@method 检测U盘是否存在可用升级文件
    bool checkUdiskUpgrade();

   private:
    static UpgradeService* sInstance;
    UpgradeServiceListener* mListener = nullptr;
    bool mIsExistUdiskUpgrade = false;
    UPGRADE_TYPE mUpgradeType = UPGRADE_TYPE_NONE;
    char mUpgradeDesc[128 * 3]; //升级描述文案
    char mUpgradeFilePath[128]; //升级文件路径

    UpgradeService();
    virtual ~UpgradeService();
};

#endif